package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.pojo.Dictionary;
import com.gxa.service.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * @program: erp
 * @description: 字典相关controller
 * @author: LC
 * @create: 2021-12-03 10:44
 */

@Controller
@RequestMapping("/dic")
@Api(value="字典，定义各种自定义选项",tags = "字典接口-自定义选项（李晨）")
public class DictionaryController {
    @Autowired(required = false)
    DictionaryService dictionaryService;


    @ApiOperation(value = "获取自定义选项的子选项",notes = "获取某自定义选项的子选项，需要父节点的dic_Name，用于指定获取哪个父节点的自定义选项", response = R.class)
    @RequestMapping(value = "/getChildDicList",method = RequestMethod.POST)
    @ResponseBody
    public R getChildDicList(@RequestBody @ApiParam Dictionary dic){
        R r=dictionaryService.getChildDic(dic);
        return r;
    }

    @ApiOperation(value = "添加自定义选项",notes = "添加一个自定义选项,添加一个字典节点需要指定父节点dic_Name（即将谁当作父节点），若不传递父节点dic_Name，默认将新增节点作为根节点", response = R.class)
    @RequestMapping(value = "/addDic",method = RequestMethod.POST)
    @ResponseBody
    public R addDic(@RequestBody @ApiParam Dictionary dic){
        R r=dictionaryService.addDic(dic);
        System.out.println(dic);
        return r;
    }


    @ApiOperation(value = "修改自定义选项",notes = "修改自定义选项，必须传递：dic_Id，其他属性为修改内容", response = R.class)
    @RequestMapping(value = "/modifyDic",method = RequestMethod.POST)
    @ResponseBody
    public R modifyDic(@RequestBody @ApiParam Dictionary dic){
        R r=dictionaryService.modifyDic(dic);
        return r;
    }

    /**
     * 问题记录，由于字典不允许重复，且删除逻辑是假删除，所以会导致
     * @param dic
     * @return
     */
    @ApiOperation(value = "删除自定义选项",notes = "删除一个自定义选项，必须传递：dic_Name，指定删除那个节点", response = R.class)
    @RequestMapping(value = "/delDic",method = RequestMethod.POST)
    @ResponseBody
    public R delDic(@RequestBody @ApiParam Dictionary dic){
        R r=dictionaryService.delDic(dic);
        return r;
    }

    @ApiOperation(value = "获取自定义选项信息",notes = "传递dic_Name，获取该节点的信息（返回的信息中包含dic_Id)", response = R.class)
    @RequestMapping(value = "/getDic",method = RequestMethod.POST)
    @ResponseBody
    public R getDic(@RequestBody @ApiParam Dictionary dic){
        R r=dictionaryService.getDic(dic);
        return r;
    }



}